$(document).ready( function(){
	$(".facebookLogin").on("click", function(){
		
	});
	$(".googleLogin").on("click", function(){
		
	});
	$(".twitterLogin").on("click", function(){
		
	});
	
	$("#loginForm button").on("click", function(){
		
		$("#ajaxLoader").show();
		
		var dataString = $("#loginForm").serialize();
		dataString += "&login=1";
		
		$.ajax({
				type:'POST',
				url: scriptsURL+"libs/ajax/ajax-includes.php",
				data: dataString,
				success: function(responseJSON)
				{
					var response = JSON.parse(responseJSON);
					var message = "";
					
					
					
						
					if(response.error_count && response.error_count > 0)
					{
						$("#ajaxLoader").hide();
						message = '<div class="alert alert-danger">'+response.message+'</div>';
						$("#messageDialog .modal-body").html(message);
						$('#messageDialog').modal('show');
						
					}
					else
					{
						//message = '<div class="alert alert-success">'+response.message+'</div>';
						
						location.reload();
					}
					
					
					
					
					$("#newCaptcha").trigger("click");
				}
		});
		return false;
	});
	
	$("#forgotPassword").on("click", function(){
		
		var userEmail = $("#loginForm #email").val();
		$("#forgotPasswordDialog input[name=email_address]").val(userEmail);
		
		$("#forgotPasswordDialog").modal("show");
		
	});
	
	$("#forgotPasswordDialog .btn.btn-danger").on("click", function(){
			$("#ajaxLoader").show();
			var email = $("#forgotPasswordDialog input[name=email_address]").val();
			dataString = "&forgot_password=1&email="+email;
			$.ajax({
				type:'POST',
				url: scriptsURL+"libs/ajax/ajax-includes.php",
				data: dataString,
				success: function(responseJSON)
				{
					response = JSON.parse(responseJSON);
					
					if(response.error_count > 0)
					{
						$("#forgotPasswordDialog .modal-body .alert").html(response.message);
						$("#forgotPasswordDialog .modal-body .alert").removeClass("hide");
					}
					else
					{
						$("#forgotPasswordDialog").modal("hide");
						$("#messageDialog .modal-body").html("<div class='alert alert-success'>"+response.message+"</div>");
						$("#messageDialog").modal("show");
					}
					$("#ajaxLoader").hide();
					
					
				}
			});
			return false;
		});
	
	$("#logout").on("click", function(){
		$("#ajaxLoader").show();
		
		dataString = "logout=1";
		
		$.ajax({
				type:'POST',
				url: scriptsURL+"libs/ajax/ajax-includes.php",
				data: dataString,
				success: function(response)
				{
					var redirectURL = $("#logo").attr("href");
					self.location= redirectURL;
					
				}
		});
		return false;
		
	});
});
